package br.com.diogenesistemas.dinggle.factory;

import br.com.diogenesistemas.dinggle.command.Command;
import java.util.ResourceBundle;

/**
 *
 * @author Diógenes
 */
public class AbstractCommandFactory {

    private static AbstractCommandFactory instance = null;
    private ResourceBundle bounder;

    private AbstractCommandFactory() {
    }

    public static AbstractCommandFactory getInstance() {
        if (instance == null) {
            instance = new AbstractCommandFactory();
        }
        return instance;
    }

    public Command getCommand(String servletPath){
        init();
        String requisicao = this.bounder.getString(servletPath);
        try {
            return (Command) Class.forName(requisicao).newInstance();            
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    private void init() {
        this.bounder = ResourceBundle.getBundle("br/com/diogenesistemas/dinggle/factory/actions");
    }
  }
